#include "QKinectManager.h"
#include "QKinect.h"

QKinect *QKinectManager::startNewKinect (
		NUI_IMAGE_TYPE depthType, NUI_IMAGE_RESOLUTION depthRes,
		NUI_IMAGE_TYPE colorType, NUI_IMAGE_RESOLUTION colorRes,
		bool bSeatedSkeletonMode, bool bNearMode, bool bFallbackToDefault)
		throw (QKinectException)
{
	size_t i = 0;
	for (; i < _kinectPtrs.size (); ++i)
		if (_kinectPtrs[i] == NULL)
			break;
	return startKinectByIndex (i, depthType, depthRes, colorType, colorRes,
			bSeatedSkeletonMode, bNearMode, bFallbackToDefault);
	return _kinectPtrs[i];
}

QKinect *QKinectManager::startKinectByIndex (size_t index,
		NUI_IMAGE_TYPE depthType, NUI_IMAGE_RESOLUTION depthRes,
		NUI_IMAGE_TYPE colorType, NUI_IMAGE_RESOLUTION colorRes,
		bool bSeatedSkeletonMode, bool bNearMode, bool bFallbackToDefault)
		throw (QKinectException)
{
	while (index >= _kinectPtrs.size ())
		_kinectPtrs.push_back (NULL);
	QKinect* pKinect = _kinectPtrs[index];
	if (pKinect == NULL)
		pKinect = _kinectPtrs[index] = new QKinect (index, depthType, depthRes,
				colorType, colorRes, bSeatedSkeletonMode, bNearMode,
				bFallbackToDefault);
	return pKinect;
}

void QKinectManager::_removeStoppedKinect (QKinect *pKinect)
{
	for (size_t i = 0; i < _kinectPtrs.size (); ++i)
		if (pKinect == _kinectPtrs[i])
			_kinectPtrs[i] = NULL;
}

std::vector< QKinect * > QKinectManager::_kinectPtrs;